<%@page import="org.proddevplm.dao.data.Roles"%>
<%@page import="java.util.List"%>
<%@page import="org.proddevplm.constants.ControllerConstants"%>
<%@page import="org.proddevplm.business.administration.constants.AdminConstants"%>
<%@page import="org.proddevplm.dao.data.administration.AccessLevel"%>

<script>

	$(document).ready(function() {
		$("#showInstructionsDiv").hide();
	});
	
	$(function(){
		$( "button" ).button();
		$("#editLevelsTable").tablesorter({
			widgets:['zebra'],
			headers:{
				1:{sorter: false},
				2:{sorter: false}
			}
		})
	});
	
	function showInstructions(){
		$("#showInstructionsDiv").show();
	}
	
	function hideInstructions(){
		$("#showInstructionsDiv").hide();
	}
	
	function editLevel(newLevel, accessLevId){
		var arguments = "accessLevelId="+accessLevId+"&newLevel="+newLevel;
		ajaxCall("adminManager", "1", arguments, null);
	}
	
	function finishEditLevels(){
		document.forms["LevelsFWD"].submit();
	}

</script>

<%
	List allRoles = (List)session.getAttribute("allRoles");
	List allAccessLevelsByProject = (List)session.getAttribute("allAccessLevelsByProject");
	Integer accessLevelId = null;

%>

<div style="width:100%;">	
			
	<div style="width:50%; float:left; ">
		<table class="tablesorter" id="editLevelsTable" border="1" cellspacing="0" cellpadding="3" rules="rows" frame="hsides" bordercolor="#DBDBDB" style="width:100%; font-family:verdana">
			<thead>
				<tr>
					<th style="text-align:left">Role</th>
					<th style="text-align:center">Current access level</th>
					<th style="text-align:center">New access level</th>
				</tr>
			</thead>
			<tbody>
				<%for (int i=0; i<allRoles.size(); i++) {
					Roles r = (Roles)allRoles.get(i);%>
				<tr>
					<td><%=r.getRole()%></td>
					<%for(int k=0; k<allAccessLevelsByProject.size(); k++){
						AccessLevel al = (AccessLevel)allAccessLevelsByProject.get(k);
						if (r.getId()==al.getRoleId()){%>
							<td style="text-align:center"><%=al.getAccessLevel() %></td>
							<%accessLevelId = al.getId();
							continue;
						} %>
					<%} %>
						
					<td style="text-align:center">
						<select name="editAccessLevel" onChange="editLevel(this.options[selectedIndex].value, '<%=accessLevelId%>')" size="1" style="width:50px">
							<%for(int j=0; j<5; j++){ %>
								<option value="<%=j %>"><%=j %></option>
							<%} %>
						</select>
					</td>
				</tr>
				<%} %>
			</tbody>
		</table>
				
		<div style="margin-top:10px; float:right">
			<button id="finishEditLevels" name="finishEditLevels" onclick="finishEditLevels()" style="width:200px; font-weight:bold">Done</button>
		</div>
				
	</div>
			
	<div id="seeHelp" style="float:left; width:48%; padding:10px">
		<button name="showInstructions" id="showInstructions" onclick="showInstructions()" style="width:40%; font-weight:bold; float:left">Show instructions</button>
		<button name="hideInstructions" id="hideInstructions" onclick="hideInstructions()" style="width:40%; font-weight:bold; float:right">Hide instructions</button>
		<div style="clear:both"></div>
		<div id="showInstructionsDiv" style="margin-top:10px; background-color:#F0F0F6; padding: 0.5%; -moz-border-radius: 5px; -moz-box-shadow: 10px 10px 5px #888888; border: 1px solid #DBDBDB; color:#555555">
			<p style="font-weight:bold">Please set the access level based on the following recommendations</p>
			<p>0 - administrator</p>
			<p>1 - project manager</p>
			<p>2 - manager</p>
			<p>3 - member - intern</p>
			<p>4 - member - extern</p>
		</div>
		
	</div>
		
	<form name="LevelsFWD" id="LevelsFWD" action="/proddev/controller">
		<input type = "hidden" name = "<%=ControllerConstants.MANAGER_KEY%>" value = "<%=ControllerConstants.ADMIN_MANAGER %>"/>
		<input type = "hidden" name = "<%=ControllerConstants.METHOD_KEY%>" value = "<%=AdminConstants.ADMIN_FWD%>"/>			
	</form>
			
	<div style="clear:both"></div>
</div>